/*
* @Author: Administrator
* @Date:   2017-12-26 15:52:28
* @Last Modified by:   'baijiwei'
* @Last Modified time: 2018-01-02 16:23:00
*/
const router = require('express').Router()
const axios = require('axios');
const qs = require('qs');
const userUrl = 'http://jhmaimai.top/news/user_login.php';
const commentsUrl = 'http://jhmaimai.top/news/comments.php';
router.post('/user_login', function (req, res) {
  axios({
    method: 'POST',
    url: userUrl,
    data: qs.stringify(req.body)
  }).then((result) => {
      if (result.status === 200 && result.data.code === 1) {
        req.session.user = result.data.data
        res.json(result.data)
      }
    })
    .catch(err => {
      if (err.response) {
        res.json({
          code: 0,
          msg: err.message,
        })
      }
    })
})
router.post('/user_logout', function (req, res) {
  req.session.user = {};
  res.json({
    code: 1,
    message: '退出登录成功'
  })
})
module.exports = router
